/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Interfaces;

import Clases.Mensualidad;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Pansho
 */
public class Mensualidades extends javax.swing.JInternalFrame {


    public Mensualidades() {
        initComponents();
    }
    
    Mensualidad m= new Mensualidad();     
    Object[][] dtPer; 
    Object[][] dtPer2; 
    int fila = -1;
    
    
       private void updateTabla(){             
        String[] columNames = {"Codigo","Rut","Personal","Año"," Mes", "Monto","Pagado"};   
        // se utiliza la funcion
        dtPer = m.getPagados(gestClientes.txtrut.getText());
        // se colocan los datos en la tabla
        DefaultTableModel datos = new DefaultTableModel(dtPer,columNames);                        
        jtpagado.setModel(datos);                      
    }
        private void updateTabla2(){             
        String[] columNames = {"Codigo","Rut","Personal","Año"," Mes", "Monto","Pagado"};   
        // se utiliza la funcion
        dtPer2 = m.getNopagados(gestClientes.txtrut.getText());
        // se colocan los datos en la tabla
        DefaultTableModel datos2 = new DefaultTableModel(dtPer2,columNames);                        
        jtnopagado.setModel(datos2);                      
    }
       
       

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtcodigo = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtrut = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtlogin = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtaño = new javax.swing.JTextField();
        txtmes = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtmonto = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtpagado = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jtnopagado = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();

        setClosable(true);
        setTitle("Pagos de "+gestClientes.txtrut.getText());
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameActivated(evt);
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Codigo Pago");

        txtcodigo.setEditable(false);

        jLabel2.setText("Rut Cliente");

        txtrut.setEditable(false);

        jLabel3.setText("Personal");

        txtlogin.setEditable(false);

        jLabel4.setText("Año");

        txtaño.setEditable(false);

        txtmes.setEditable(false);

        jLabel5.setText("Mes");

        jLabel6.setText("Monto");

        txtmonto.setEditable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtrut, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
                    .addComponent(txtcodigo))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtlogin)
                    .addComponent(txtaño, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtmes)
                    .addComponent(txtmonto, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtrut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(txtlogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(txtmonto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtcodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(txtaño, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(txtmes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(35, Short.MAX_VALUE))
        );

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Pagados"));

        jtpagado.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Codigo", "Rut", "Personal", "Año", "Mes", "Monto", "Pagado"
            }
        ));
        jtpagado.setEnabled(false);
        jtpagado.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtpagadoMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jtpagado);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/coins.png"))); // NOI18N
        jButton1.setText("Pagar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jScrollPane3.setBorder(javax.swing.BorderFactory.createTitledBorder("No Pagados"));

        jtnopagado.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Codigo", "Rut", "Personal", "Año", "Mes", "Monto", "Pagado"
            }
        ));
        jtnopagado.setEnabled(false);
        jtnopagado.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtnopagadoMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(jtnopagado);

        jButton2.setText("No Pagado");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(10, 10, 10))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(18, 18, 18)
                .addComponent(jButton1))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 664, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formInternalFrameActivated(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameActivated
        Mensualidad m=new Mensualidad();
        Object[][] dtPer;  
        Object[][] dtPer2;   
        String[] columNames = {"Codigo","Rut","Personal","Año"," Mes", "Monto","Pagado"};  
        //String[] columNames = {"LOGIN_PERSONAL","CLAVE_PERSONAL","NOMBRE_PERSONAL","CARGO_PERSONAL"};  
        // se utiliza la funcion
        dtPer = m.getPagados(gestClientes.txtrut.getText());
        dtPer2 = m.getNopagados(gestClientes.txtrut.getText());
        
        // se colocan los datos en la tabla
        DefaultTableModel datos = new DefaultTableModel(dtPer,columNames);  
        DefaultTableModel datos2 = new DefaultTableModel(dtPer2,columNames);  
        jtpagado.setModel(datos);
        jtnopagado.setModel(datos2);
        updateTabla(); 
        updateTabla2();// TODO add your handling code here:
    }//GEN-LAST:event_formInternalFrameActivated

    private void jtnopagadoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtnopagadoMouseClicked
            fila = jtnopagado.rowAtPoint(evt.getPoint());                 
        if (fila> -1){                          
             txtcodigo.setText(String.valueOf(jtnopagado.getValueAt(fila, 0)));
            txtrut.setText(String.valueOf(jtnopagado.getValueAt(fila, 1)));
            txtlogin.setText(String.valueOf(jtnopagado.getValueAt(fila, 2)));
            txtaño.setText(String.valueOf(jtnopagado.getValueAt(fila, 3)));
            txtmes.setText(String.valueOf(jtnopagado.getValueAt(fila, 4)));
            txtmonto.setText(String.valueOf(jtnopagado.getValueAt(fila, 5)));
        }   
    }//GEN-LAST:event_jtnopagadoMouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    if (fila> -1){
        int cod = Integer.parseInt(txtcodigo.getText());
        m.Pagar(cod);
        updateTabla();
        updateTabla2();
    }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        if (fila> -1){
        int cod = Integer.parseInt(txtcodigo.getText());
        m.Nopagado(cod);
        updateTabla();
        updateTabla2();
    }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jtpagadoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtpagadoMouseClicked
                   fila = jtpagado.rowAtPoint(evt.getPoint());                 
        if (fila> -1){                          
             txtcodigo.setText(String.valueOf(jtpagado.getValueAt(fila, 0)));
            txtrut.setText(String.valueOf(jtpagado.getValueAt(fila, 1)));
            txtlogin.setText(String.valueOf(jtpagado.getValueAt(fila, 2)));
            txtaño.setText(String.valueOf(jtpagado.getValueAt(fila, 3)));
            txtmes.setText(String.valueOf(jtpagado.getValueAt(fila, 4)));
            txtmonto.setText(String.valueOf(jtpagado.getValueAt(fila, 5)));
        }   
    }//GEN-LAST:event_jtpagadoMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jtnopagado;
    private javax.swing.JTable jtpagado;
    private javax.swing.JTextField txtaño;
    private javax.swing.JTextField txtcodigo;
    private javax.swing.JTextField txtlogin;
    private javax.swing.JTextField txtmes;
    private javax.swing.JTextField txtmonto;
    private javax.swing.JTextField txtrut;
    // End of variables declaration//GEN-END:variables
}
